<template>
  <v-app id="inspire">
    <v-content>
      <v-container
      >
        <v-snackbar
        v-model="snackbar"
      >
        {{ text }}
        <v-btn
          color="pink"
          text
          @click="snackbar = false"
        >
          Close
        </v-btn>
      </v-snackbar>
        <h1>{{this.$route.params.id}}</h1>
        <h3 style="color: #0077B5">{{this.$route.query.fileTitle}}</h3>
        <v-form v-model="valid"
                ref="form"
        >
          <v-textarea
            v-model="comments"
            :rules="[v => !!v || 'Item is required']"
            label="Comments"
            name="Comments"
            type="text"
          />

          <v-btn @click="submitRebuttal">Submit</v-btn>
        </v-form>
        <side-bar></side-bar>
      </v-container>
    </v-content>
  </v-app>
</template>

<script>
  import SideBar from './Components/SideBar'
  import store from '../store'
  export default {
    name: 'Rebuttal',
    components: {SideBar},
    data() {
      return{
        text: '',
        comments: '',
        snackbar: false,
        test: ''
      }
    },
    methods:{
      submitRebuttal() {
        this.$axios.post('/sendRebuttal', {
          title: this.$route.query.fileTitle,
          meetingFullName: this.$route.params.id,
          contributor: store.state.userName,
          comments: this.comments
        })
          .then(resp => {
            console.log(resp.data)
            if (resp.status === 200) {
              if (resp.data.hasOwnProperty('title')) {
                this.text = 'rebuttal succeed'
                this.snackbar = true
                this.$router.push({
                  path: '/workspace'
                })
              } else {
                this.text = '只能rebuttal一次哦'
                this.snackbar = true
              }
            } else {
              this.text = 'error'
              this.snackbar = true
            }
          })
          .catch(error => {
            this.text = 'error!'
            this.snackbar = true
          })
      }
    }
  }
</script>
